<template>
  <div>
    <router-view />
    <div>合作券商：南京证券。 全自动交易开通申请咨询热线：0571-82310420</div>
  </div>
</template>

<script>
import { createSocket, socketsend } from '../src/assets/js/websocketTest.js'
import CryptoJS from 'crypto-js'
export default {
  data() {
    return {
      loginForm: {
        num: '',
        password: ''
      }
    }
  },
  created() {
    console.log('刷新了一下')
    this.getCookie()
    this.login()
    setTimeout(() => {
      socketsend()
    }, 1000)
  },
  methods: {
    // 解密函数
    Decrypt(b) {
      var bytes = CryptoJS.AES.decrypt(b, 'secretkey123')
      var originalText = bytes.toString(CryptoJS.enc.Utf8)
      console.log(originalText)
      return originalText
    },
    // 读取cookie
    getCookie: function() {
      if (document.cookie.length > 0) {
        var arr = document.cookie.split('; ') // 这里显示的格式需要切割一下自己可输出看下
        for (var i = 0; i < arr.length; i++) {
          var arr2 = arr[i].split('=') // 再次切割
          console.log(arr2)
          // 判断查找相对应的值
          if (arr2[0] === 'num') {
            this.loginForm.num = arr2[1]
            // var bytes1 = CryptoJS.AES.decrypt(arr2[1], 'secretkey123')
            // this.loginForm.num = bytes1.toString(CryptoJS.enc.Utf8) - 0 // 保存到保存数据的地方
          } else if (arr2[0] === 'password') {
            this.loginForm.password = this.Decrypt(arr2[1])
            // var bytes2 = CryptoJS.AES.decrypt(arr2[1], 'secretkey123')
            // this.password = bytes2.toString(CryptoJS.enc.Utf8)
          }
        }
      }
    },
    login() {
      this.$store.state.Num = this.loginForm.num
      this.$store.state.Password = this.loginForm.password
      this.$store.state.type = '1'
      console.log('这里重新建立了一次连接')
      // createSocket('ws://192.168.199.205:6060/test')
      createSocket('ws://47.99.175.180:6060/test')
      // createSocket('ws://192.168.199.128:6060/test')
    }
  }
}
</script>
